
import * as cc from "cc";
import { Locator } from "../../../framework/utils/Locator";
const { ccclass, } = cc._decorator;

/**
 * Predefined variables
 * Name = PageBase
 * DateTime = Sun Mar 20 2022 13:27:14 GMT+0800 (中国标准时间)
 * Author = 272493431
 * FileBasename = PageBase.ts
 * FileBasenameNoExtension = PageBase
 * URL = db://assets/scripts/scene/VMDemo/page/PageBase.ts
 * ManualUrl = https://docs.cocos.com/creator/3.4/manual/zh/
 *
 */
 
@ccclass('PageBase')
export class PageBase {
   
    pageName: string;

    node: cc.Node;
    
    // 缓存下查找过的结点
    nodeCache: Record<string,cc.Node> = {};

    onCtor(node: cc.Node){
        this.node = node;
        this.pageName = node.name;
        this.onLoaded();
    }
    
    onLoaded(){

    }

    onUnloaded(){

    }

    /**
     * 窗口激活
     */
    onActive(){
        console.log(`PageBase-> ${this.pageName} 激活`);
        
    }

    /**
     * 窗口冻结
     */
    onFreeze(){
        console.log(`PageBase-> ${this.pageName} 冻结`);
    }

    find(path: string,refresh?: boolean){
        let node = this.nodeCache[path];

        if(refresh || !node){
            node = Locator.locateNode(this.node,path);
        }

        if(node){
            this.nodeCache[path] = node;
        }
        return node;
    }
}
